from pyecharts.charts import Pie
from pyecharts import options as opts

# 数据和标签
data_pair = [
    ("前端", 9509),
    ("软件", 7522),
    ("运维", 6774),
    ("Java", 4446),
    ("Android", 3053),
    ("数据", 2106),
    ("算法", 1619),
    ("安卓", 749),
    ("图像", 490),
    ("人工智能", 224),
]

# 创建饼图
pie = (
    Pie()
    .add(
        series_name="",
        data_pair=data_pair,
        radius=["40%", "55%"],  # 设置内外半径
    )
    .set_global_opts(
        title_opts=opts.TitleOpts(title="各类岗位占比", pos_left="center"),
        legend_opts=opts.LegendOpts(orient="vertical", pos_top="15%", pos_right="2%"),
    )
    .set_series_opts(
        label_opts=opts.LabelOpts(formatter="{b}: {c} ({d}%)")  # 设置标签显示格式
    )
    .set_colors(["#4B79A1", "#58D68D", "#F7C46C", "#E14A5B", "#8A2BE2", "#A1C4CF", "#F4A460", "#DA70D6", "#FFC0CB", "#FF69B4"])
)

# 渲染图表到 HTML 文件
pie.render("6.2(5) 各类岗位占比.html")